import {
  exportUrl,
  getDeliveryMethodList,
  exportAll,
} from "@/api/order/mesSalesOrder";
import url from "@/axios/url";
import excelUpload from "@/components/excel-upload/excelUpload";

const { mesUrl } = url();
// 列表头按钮配置
export const operateList = {
  data() {
    const _this = this;
    return {
      operateList: [
        {
          name: $i18n.t("common.export"),
          type: "primary",
          icon: "el-icon-download",
          handleName: "export", //点击时返回的标识
          url: exportUrl,
          //auth: "auth:operlog:export", //权限字段
        },
        {
          name: $i18n.t("common.add"),
          type: "primary",
          icon: "el-icon-circle-plus-outline",
          handleName: "add", //点击时返回的标识
        },
        {
          name: $i18n.t("common.delete"),
          type: "danger",
          icon: "el-icon-delete",
          isMultiple: true,
          handleName: "deleteBatch", //点击时返回的标识
        },

        {
          // 导入文件
          render: (h, scope) => {
            // scope列表上选择的数据
            const uploadUrl = `${mesUrl}mesSalesOrder/importData`;
            return (
              <excelUpload
                action={uploadUrl}
                on={{
                  handleUploadError: (err) => {
                    // 失败的回调
                    console.log(err);
                  },
                  handleUploadSuccess: (res) => {
                    _this.$refs.eleTable.handleReset();
                    //成功 的回调
                  },
                }}
              />
            );
          },
        },
        {
          name: $i18n.t("mesSalesOrder.exportDetails"),
          type: "primary",
          icon: "el-icon-download",
          handleName: "export", //点击时返回的标识
          url: exportAll,
          //auth: "auth:operlog:export", //权限字段
        },
        {
          // 导入文件
          render: (h, scope) => {
            // scope列表上选择的数据
            const uploadUrl = `${mesUrl}mesSalesOrderDetail/importData`;
            return (
              <excelUpload
                buttonTxt={$i18n.t("mesSalesOrder.importDetails")}
                action={uploadUrl}
                on={{
                  handleUploadError: (err) => {
                    //失败 的回调
                  },
                  handleUploadSuccess: (res) => {
                    _this.$refs.eleTable.handleReset();
                    //成功 的回调
                  },
                }}
              />
            );
          },
        },
        {
          name: $i18n.t("common.downloadTemplate"),
          type: "success",
          icon: "el-icon-download",
          handleName: "exportExcel", //点击时返回的标识
        },
      ],
    };
  },
};

// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    salesOrderCode: {
      type: "input",
      label: $i18n.t("mesSalesOrder.salesOrderCode"),
    },
    customerCode: {
      type: "input",
      label: $i18n.t("mesSalesOrder.customerCode"),
    },
    customerName: {
      type: "input",
      label: $i18n.t("mesSalesOrder.customerName"),
    },
    deliveryMethod: {
      label: $i18n.t("mesSalesOrder.deliveryMethod"),
      type: "select",
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getDeliveryMethodList();
        return list.data.result;
      },
    },
    customerOrderCode: {
      type: "input",
      label: $i18n.t("mesSalesOrder.customerOrderCode"),
    },
    planDeliveryDate: {
      type: "daterange",
      label: $i18n.t("mesSalesOrder.planDeliveryDate"),
      attrs: {
        valueFormat: "yyyy-MM-dd",
        searchArrKey: ["planDeliveryDateMin", "planDeliveryDateMax"],
      },
    },
  },
};
